package com.youcan.service.serviceimpl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.springframework.beans.factory.annotation.Autowired;

import com.youcan.dao.BaseDao;
import com.youcan.service.Service;

/**
 * @author LiChao E-mail:what_is_javascript@163.com
 * @date:2012-8-24 上午12:15:52
 * @version :V1.0
 *
 */
public class ServiceImpl<T> implements Service<T> {
 
	@Autowired
	private BaseDao<T> baseDao;
	@Override
	public T addEntity(T object) {
		// TODO Auto-generated method stub
		return baseDao.save(object);
	}

	@Override
	public void deleteEntity(T object) {
		// TODO Auto-generated method stub
		baseDao.delete(object);
		
	}

	@Override
	public T updateEntity(T object) {
		// TODO Auto-generated method stub
		return baseDao.save(object);
	}

	@Override
	public T findById(String className,Serializable id) {
		// TODO Auto-generated method stub
		
		return baseDao.findById(className,id);
	}

	@Override
	public T findByIdAndLock(String className,Serializable id, boolean lock) {
		// TODO Auto-generated method stub
		return baseDao.findById(className,id, lock);
	}

	@Override
	public List<T> findAll(String className) {
		// TODO Auto-generated method stub
		return baseDao.findAll(className);
	}

	@Override
	public List<T> findByCriteria(Object... objects) {
		// TODO Auto-generated method stub
		return baseDao.findByCriteria((Criterion[]) objects);
	}

	@Override
	public List<T> findByProp(String className,String property, Object value) {
		// TODO Auto-generated method stub
		return baseDao.findByProperty(className,property, value);
	}

	@Override
	public T findUniqueByProp(String className,String property, Object value) {
		// TODO Auto-generated method stub
		return baseDao.findSingleByProperty(className,property, value);
	}

}
